//
//  MOSignPasswordView.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/8/5.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#import "MOSignPasswordView.h"

@interface MOSignPasswordView ()

@property(nonatomic,strong)UIView *backView;

@property(nonatomic,strong)UITextField *textField;

@end

@implementation MOSignPasswordView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self) {
        
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.7];
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [button addTarget:self action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        
        [self addSubview:self.backView];
    }
    return self;
}

#pragma mark -- 取消
-(void)clickCancelButton
{
    self.frame = CGRectMake(0, 0, 0, 0);
    self.backView.frame = CGRectMake(0, 0, 0, 0);
}

#pragma mark -- 确定
-(void)clickSureButton
{
    if (self.textField.text.length==0) {
        [[ADShowMessage shareShowMessage]showTextOnly:@"先输入签字密码" showInView:WINDOW];
    }else{
        [self clickCancelButton];
        
        if (self.clickSureButtonBlock) {
            self.clickSureButtonBlock(self.textField.text);
        }
    }
}



#pragma mark -- 懒加载
-(UIView *)backView
{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWConversions(280), 160)];
        _backView.centerX = SCREEN_WIDTH/2;
        _backView.centerY = SCREEN_HEIGHT/2 - StatusBarAndNavigationBarHeight;
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.masksToBounds = YES;
        _backView.layer.cornerRadius = 13.0;
//        _backView.layer.borderWidth = 2;
//        _backView.layer.borderColor = KGrayColor_ededed.CGColor;
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, _backView.width - 20, 17)];
        label.text = @"签字密码:";
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = KBlackColor_222222;
        label.font = FONT_SIZE(15);
        [_backView addSubview:label];
        
        _textField = [[UITextField alloc]initWithFrame:CGRectMake(20, label.bottom + 15, _backView.width - 40, 35)];
        _textField.font = FONT_SIZE(15);
        _textField.textColor = KBlueColor_2C94FF;
        _textField.layer.masksToBounds = YES;
        _textField.layer.cornerRadius = 4.0;
        _textField.layer.borderWidth = 1;
        _textField.layer.borderColor = KGrayColor_ededed.CGColor;
        _textField.textAlignment = NSTextAlignmentCenter;
        [_backView addSubview:_textField];
        
        UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(0, _backView.height - 50, _backView.width, 1)];
        line1.backgroundColor = KGrayColor_ededed;
        [_backView addSubview:line1];
        
        UIButton *cancelButton = [[UIButton alloc]initWithFrame:CGRectMake(0, line1.bottom, _backView.width/2, 49)];
        [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
        cancelButton.titleLabel.font = FONT_SIZE(13);
        [cancelButton setTitleColor:KBlackColor_222222 forState:UIControlStateNormal];
        [cancelButton addTarget:self action:@selector(clickCancelButton) forControlEvents:UIControlEventTouchUpInside];
        [_backView addSubview:cancelButton];
        
        UIButton *sureButton = [[UIButton alloc]initWithFrame:CGRectMake(cancelButton.right, line1.bottom, _backView.width/2, 49)];
        [sureButton setTitle:@"确定" forState:UIControlStateNormal];
        sureButton.titleLabel.font = FONT_SIZE(13);
        [sureButton setTitleColor:KBlackColor_222222 forState:UIControlStateNormal];
        [sureButton addTarget:self action:@selector(clickSureButton) forControlEvents:UIControlEventTouchUpInside];
        [_backView addSubview:sureButton];
        
        
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(_backView.width/2, _backView.height - 49, 1, 49)];
        line2.backgroundColor = KGrayColor_ededed;
        [_backView addSubview:line2];
        
    }
    return _backView;
}

@end
